home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.5 KB | 370 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCmd.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCMD_H
- #include "FWCmd.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWITEXT_H
- #include "FWIText.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- // for ODIText
- #ifndef SOM_ODPart_xh
- #include "Part.xh"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include "Frame.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- #if defined(FW_BUILD_WIN32S) && !defined(__WINNT_H)
- #include <winnt.h>
- #endif
-
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkCommands
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CCommand)
-
- //========================================================================================
- // FW_CCommand class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand constructor
- //----------------------------------------------------------------------------------------
-
- FW_CCommand::FW_CCommand(Environment* ev,
- ODCommandID id,
- FW_CFrame* frame,
- FW_Boolean canUndo) :
- fCommandID(id),
- fCanUndo(canUndo),
- fCausesChange(TRUE),
- fActionType(kODSingleAction),
- fPart(NULL),
- fFrame(frame),
- fSelection(NULL),
- fUndoString(NULL),
- fRedoString(NULL),
- fUndo(NULL),
- fHasAddedAction(FALSE)
- {
- FW_ASSERT(fFrame);
-
- fPart = frame->GetPart(ev);
- fSelection = frame->GetPresentation(ev)->GetSelection(ev);
-
- fPart->GetODPart(ev)->Acquire(ev);
-
- fUndo = fPart->GetSession(ev)->GetUndo(ev);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand destructor
- //----------------------------------------------------------------------------------------
-
- FW_CCommand::~FW_CCommand()
- {
- FW_START_DESTRUCTOR
-
- Environment *ev = somGetGlobalEnvironment();
-
- fPart->GetODPart(ev)->Release(ev);
-
- PrivDisposeUndoStrings();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::PrivDisposeUndoStrings
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::PrivDisposeUndoStrings()
- {
- if (fUndoString)
- ::DisposeIText(fUndoString);
- if (fRedoString)
- ::DisposeIText(fRedoString);
-
- fUndoString = fRedoString = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::PerformCommand
- //----------------------------------------------------------------------------------------
-
- FW_DECLARE_THROW_POINT(FW_CCommand_PerformCommand_AfterDoIt);
- FW_DECLARE_THROW_POINT(FW_CCommand_PerformCommand_AfterChanged);
-
- void FW_CCommand::PerformCommand(Environment* ev)
- {
- this->DoIt(ev);
-
- if (fCausesChange) {
- FW_TRY {
- FW_CHECK_THROW_POINT(FW_CCommand_PerformCommand_AfterDoIt);
- fPart->Changed(ev);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- // XXX What if we're linking?
- fCanUndo = FALSE; // XXX is this a good idea? Should we throw again?
- }
- FW_CATCH_END
- }
-
- if (fCanUndo)
- {
- FW_TRY {
- FW_CHECK_THROW_POINT(FW_CCommand_PerformCommand_AfterChanged);
- // Make sure we don't pass NULL menu strings to OpenDoc!
- FW_ASSERT(fUndoString != NULL);
- FW_ASSERT(fRedoString != NULL);
-
- this->AddAction(ev, fActionType, (octet*) &this, sizeof(FW_CCommand*),
- fUndoString, fRedoString);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- // It would be nice if we could put up a dialog saying
- // this isn't undoable; but we can't continue the
- // exception or the caller will assume *everything*
- // failed.
- fCanUndo = false;
- }
- FW_CATCH_END
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::UndoIt(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::RedoIt(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::CommitDone
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::CommitDone(Environment* ev)
- {
- // Called by FW_CPart::DisposeActionState before deleting the command
- // The command has been done, and possibly redone
-
- if (fCanUndo)
- this->FreeUndoState(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::CommitUndone
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::CommitUndone(Environment* ev)
- {
- // Called by FW_CPart::DisposeActionState before deleting the command
- // The last action for this command was an Undo
-
- if (fCanUndo)
- this->FreeRedoState(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void FW_CCommand::SaveUndoState(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void FW_CCommand::SaveRedoState(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void FW_CCommand::FreeUndoState(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void FW_CCommand::FreeRedoState(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetMenuStrings
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::SetMenuStrings(Environment* ev,
- const FW_CString& undoString,
- const FW_CString& redoString)
- {
- if (!fCanUndo)
- return;
-
- FW_TRY
- {
- PrivDisposeUndoStrings();
- fUndoString = ::CreateITextString(undoString);
- fRedoString = ::CreateITextString(redoString);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- PrivDisposeUndoStrings();
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetMenuStrings
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::SetMenuStrings(Environment* ev,
- char* undoChars,
- char* redoChars)
- {
- FW_CString255 undoString(undoChars);
- FW_CString255 redoString(redoChars);
- this->SetMenuStrings(ev, undoString, redoString);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::AddAction
- //----------------------------------------------------------------------------------------
-
- void FW_CCommand::AddAction(Environment* ev, ODActionType actionType,
- octet* dataPtr, unsigned long dataSize,
- ODName* undoActionLabel, ODName* redoActionLabel)
- {
- // Set up the action data record
- ODActionData actionState;
- actionState._maximum = dataSize;
- actionState._length = dataSize;
- actionState._buffer = dataPtr;
-
- fUndo->AddActionToHistory(ev, fPart->GetODPart(ev),
- &actionState,
- actionType,
- undoActionLabel,
- redoActionLabel);
- if (dataSize != 0)
- fHasAddedAction = TRUE; // OpenDoc has a ptr to this command object
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::IsOKtoEdit
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CCommand::IsOKtoEdit(Environment* ev)
- {
- FW_Boolean result = TRUE;
-
- if (fCausesChange)
- {
- if (fPart->IsReadOnly(ev))
- result = FALSE;
- else
- {
- // Check the frame's link status to see if editing is allowed
- FW_ASSERT(fFrame != NULL);
- ODLinkStatus status = fFrame->GetODFrame(ev)->GetLinkStatus(ev);
- if (status == kODInLinkDestination)
- {
- // uh-oh, make sure Part::EditInLinkAttempted is called
- result = fFrame->GetODFrame(ev)->EditInLink(ev);
- }
- }
- }
-
- return result;
- }
-
-